package usr

import (
	"github.com/gin-gonic/gin"
)

// 批量创建 base_usr
func Create(c *gin.Context) {
	var form BaseUsr
	c.Bind(&form)
	target, err := NewBaseUsrService().CreateUsr(&form)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
	}
	c.JSON(200, target)
}

// 根据 ids 删除 base_usr
func DeleteById(c *gin.Context) {
	id := BaseUsrId(c.Param("id"))
	err := NewBaseUsrService().DeleteUsrById(&id)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
	}
	c.JSON(200, gin.H{"success": true})
}

// 根据 id 修改 base_usr
func UpdateById(c *gin.Context) {
	id := BaseUsrId(c.Param("id"))
	var form BaseUsr
	c.Bind(&form)
	err := NewBaseUsrService().UpdateUsrById(&id, &form)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
	}
	c.JSON(200, gin.H{"success": true})
}

// 根据搜索条件和分页查找 base_usr 列表
func FindAll(c *gin.Context) {
	list, err := NewBaseUsrService().FindAllUsr()
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
	}
	c.JSON(200, list)
}
